﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MVC4Shop.Models;
using System.Data;
using System.Data.SqlClient;

namespace MVC4Shop.dao
{
    public class ProductDAO
    {
        public static List<ProductModel> GetAll()
        {
            return Convert(DataUtil.executeStore("sp_Product_GetAll", null));
        }

        public static Boolean Insert(SizeModel _model)
        {
            SqlParameter[] param = new SqlParameter[1];
            int i = 0;
            param[i] = new SqlParameter("@name", SqlDbType.NVarChar);
            param[i++].Value = _model.name;
            return DataUtil.executeNonStore("sp_Size_Insert", param);
        }

        public static List<ProductModel> Convert(DataTable dt)
        {
            List<ProductModel> list = new List<ProductModel>();
            ProductModel model;
            if (dt != null)
                foreach (DataRow row in dt.Rows)
                {
                    model = new ProductModel();
                    model.id = row["product_id"].ToString();
                    model.name = row["name"].ToString();
                    model.image = row["image"].ToString();
                    model.price = row["price"].ToString();
                    model.details = row["details"].ToString();
                    model.category_id = row["category_id"].ToString();
                    //model.catategory_name = row[""].ToString();
                    list.Add(model);
                }
            return list;
        }

    }
}